<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="lhy.autoparts.menu.IndexMenuService" %>
<%@ page import="lhy.autoparts.pojo.IndexMenu" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.stream.Collectors" %>
<%@ page language="java" pageEncoding="UTF-8" %>
<html lang="en" class="light-style layout-menu-fixed" dir="ltr" data-theme="theme-default"
      data-assets-path="../../assets/" data-template="vertical-menu-template-free">
<head>
    <jsp:include page="__header.jsp"/>
    <title>众合汽配数据通</title>
</head>

<body>
<!-- Layout wrapper -->
<div class="layout-wrapper layout-content-navbar">
    <div class="layout-container">
        <!-- Menu -->

        <aside id="layout-menu" class="layout-menu menu-vertical menu bg-menu-theme">
            <div class="app-brand demo">
                <a href="index.html" class="app-brand-link">
              <span class="app-brand-logo demo">
              <i class="fa fa-car"></i>
              </span>
                    <span class="app-brand-text demo menu-text fw-bolder ms-2" style="font-size:20px">众合汽配</span>
                </a>

                <a href="javascript:void(0);" class="layout-menu-toggle menu-link text-large ms-auto d-block d-xl-none">
                    <i class="bx bx-chevron-left bx-sm align-middle"></i>
                </a>
            </div>

            <div class="menu-inner-shadow"></div>
            <!--  侧边栏 -->


            <ul class="menu-inner py-1" id="sidebar">

                <!-- Dashboard -->
                <li class="menu-item">
                    <a href="javascript:jump('home.jsp',this)" class="menu-link">
                        <i class="menu-icon tf-icons bx bx-home-circle"></i>
                        <div>首页</div>
                    </a>
                </li>
                <%
                    List<IndexMenu> allMenu = IndexMenuService.getAllMenu();
                    List<IndexMenu> collect =   allMenu.stream().filter(indexMenu -> indexMenu.pid == 0).collect(Collectors.toList());
                    for(IndexMenu menu:collect){ %>
                    <li class="menu-item">
                        <a href="javascript:void(0);" class="menu-link menu-toggle">
                            <i class="menu-icon tf-icons bx <%=menu.icon%>"></i>
                            <div><%=menu.name%>
                            </div>
                        </a>
                        <ul class="menu-sub">
                            <% List<IndexMenu> collectSub = allMenu.stream().filter(menu2->menu2.pid==menu.id).collect(Collectors.toList());
                            for(IndexMenu menu2:collectSub){%>
                            <li class="menu-item" onclick="jump('<%=menu2.voClass%><%=menu2.name.contains("统计")?"Stat":""%>',this)">
                                <a href="javascript:void(0)" class="menu-link">
                                    <div><%=menu2.name%></div>
                                </a>
                            </li>
                            <%}%>


                        </ul>
                    </li>
                <% } %>




            </ul>
        </aside>
        <!-- / Menu -->
        <!-- Layout container -->
        <div class="layout-page">
            <!-- Content wrapper -->
            <div class="content-wrapper">
                <!-- Content -->
                <iframe width="100%" height="100%" id="frame" src="home.jsp"></iframe>

            </div>
            <!-- / Content -->

            <div class="content-backdrop fade"></div>
        </div>
        <!-- Content wrapper -->
    </div>
    <!-- / Layout page -->
</div>

<!-- Overlay -->
<div class="layout-overlay layout-menu-toggle"></div>
</div>
<!-- / Layout wrapper -->


<jsp:include page="__footer.jsp"/>
<script type="text/javascript">
    var activeElement;

    function jump(clazz, element) {
        if(clazz.endsWith('.jsp')){
            document.getElementById("frame").src=clazz;
        }else if(clazz.endsWith('Stat')){
            document.getElementById("frame").src="${pageContext.request.contextPath}/StatsServlet?entityClassName=lhy.autoparts.pojo."+clazz.replace('Stat','');
        }

        else
             document.getElementById("frame").src =  "${pageContext.request.contextPath}/CrudPreprocessServlet?entityClassName=lhy.autoparts.pojo."+clazz;
        if (activeElement !== undefined) {
            activeElement.classList.remove('active');
        }
        element.classList.add('active');
        activeElement = element;
    }

</script>
</body>
</html>